package com.trkj.controller;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.trkj.pojo.Emp;
import com.trkj.pojo.Leave;
import com.trkj.service.LeaveService;
import com.trkj.vo.LeaveVo;

/**
 * 请假申请
 * @author 彭帅
 *
 */
@Controller
@Transactional
@SessionAttributes({"emp", "funcIds"})
public class LeaveController {
	@Autowired
	LeaveService leaveService;
	/**
	 * 填写请假申请表单
	 * @return
	 */
	@RequestMapping("/to_leave")
	public String leave() {
		return "to_leave";
	}
	/**
	 * 获取请假信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/get_leave")
	@ResponseBody
	public LeaveVo getleave(Model model) {
		Emp emp = (Emp) model.asMap().get("emp");
		Integer empid = emp.getEmpId();
		return leaveService.leaveVo(empid);
	}
	/**
	 * 请假申请单暂存
	 * @param leave
	 * @param deptId
	 * @param positionId
	 * @param empId
	 * @return
	 */
	@RequestMapping("/save_leave")
	@ResponseBody
	public boolean save_leave(Leave leave,Integer empId,Integer deptId,Integer positionId) {
		Integer isSave = leaveService.save_leave(leave, positionId, empId ,deptId);
		if (isSave!=0) {
			return true;
		}
		return false;
	}
}
